home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / sndhrdw / polyplay.c < prev    next >
C/C++ Source or Header  |  2000-04-22  |  2KB  |  92 lines

  1. /***************************************************************************
  2.  
  3.   Poly-Play
  4.   (c) 1985 by VEB Polytechnik Karl-Marx-Stadt
  5.  
  6.   sound hardware
  7.  
  8.   driver written by Martin Buchholz (buchholz@mail.uni-greifswald.de)
  9.  
  10. ***************************************************************************/
  11. #include "driver.h"
  12. #include <math.h>
  13.  
  14. #define LFO_VOLUME 25
  15. #define SAMPLE_LENGTH 32
  16. #define SAMPLE_AMPLITUDE 0x4000
  17.  
  18. static int freq1, freq2, channellfo, channel_playing1, channel_playing2;
  19. int lfovol[2] = {LFO_VOLUME,LFO_VOLUME};
  20.  
  21. const double pi = 3.14159265359;
  22.  
  23. static INT16 backgroundwave[SAMPLE_LENGTH];
  24.  
  25. int polyplay_sh_start(const struct MachineSound *msound)
  26. {
  27.     int i;
  28.  
  29.     for (i = 0; i < SAMPLE_LENGTH / 2; i++) {
  30.         backgroundwave[i] = + SAMPLE_AMPLITUDE;
  31.     }
  32.     for (i = SAMPLE_LENGTH / 2; i < SAMPLE_LENGTH; i++) {
  33.         backgroundwave[i] = - SAMPLE_AMPLITUDE;
  34.     }
  35.     freq1 = freq2 = 110;
  36.     channellfo = mixer_allocate_channels(2,lfovol);
  37.     mixer_set_name(channellfo+0,"Polyplay #0");
  38.     mixer_set_name(channellfo+1,"Polyplay #1");
  39.     mixer_set_volume(channellfo+0,0);
  40.     mixer_set_volume(channellfo+1,0);
  41.  
  42.     channel_playing1 = 0;
  43.     channel_playing2 = 0;
  44.     return 0;
  45. }
  46.  
  47. void polyplay_sh_stop(void)
  48. {
  49.     mixer_stop_sample(channellfo+0);
  50.     mixer_stop_sample(channellfo+1);
  51. }
  52.  
  53. void polyplay_sh_update(void)
  54. {
  55.     mixer_set_sample_frequency(channellfo+0, sizeof(backgroundwave)*freq1 );
  56.     mixer_set_sample_frequency(channellfo+1, sizeof(backgroundwave)*freq2 );
  57. }
  58.  
  59. void set_channel1(int active)
  60. {
  61.     channel_playing1 = active;
  62. }
  63.  
  64. void set_channel2(int active)
  65. {
  66.     channel_playing2 = active;
  67. }
  68.  
  69. void play_channel1(int data)
  70. {
  71.     if (data) {
  72.         freq1 = 2457600 / 16 / data / 8;
  73.         mixer_set_volume(channellfo+0, channel_playing1 * 100);
  74.         mixer_play_sample_16(channellfo+0, backgroundwave, sizeof(backgroundwave), sizeof(backgroundwave)*freq1,1);
  75.     }
  76.     else {
  77.         polyplay_sh_stop();
  78.     }
  79. }
  80.  
  81. void play_channel2(int data)
  82. {
  83.     if (data) {
  84.         freq2 = 2457600 / 16 / data / 8;
  85.         mixer_set_volume(channellfo+1, channel_playing2 * 100);
  86.         mixer_play_sample_16(channellfo+1, backgroundwave, sizeof(backgroundwave), sizeof(backgroundwave)*freq2,1);
  87.     }
  88.     else {
  89.         polyplay_sh_stop();
  90.     }
  91. }
  92.